<!--新版转盘-->
<div id="J_GameRotateC" data-game-switch="true">
<link rel="stylesheet" href="<%- Virtual_Path.Static %>main/template/imax/css/luckylottery.css"/>
<script src="<%- Virtual_Path.Static %>/jquery.plugin/rotate/jquery.rotate.min.js"></script>
    <!-- 大转盘抽奖 -->
    <div class="modal-luckylottery-box" style="left: 255px;bottom: 73px;">
        <div class="luckylottery-closed" id="J_RotateClosed"></div>
        <div class="luckylottery-content">
            <div class="lottery-game">
                <div class="lottery-game-c">
                    <div class="g-lottery-box">
                        <div class="g-lottery-img g-lottery-img-1" id="J_G_LotteryImg">
                            <a class="playbtn" href="javascript:;" title="开始抽奖" id="J_GamePlayBtn">
                            </a>
                            <div class="playbtntxt" style="left:129px;top:129px;">
                                <img id="J_GameLotteryPlayImg" src="<%- Virtual_Path.Static %>main/template/imax/image/lottery/rotate/lottery/playbtn-4.png" alt="">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="lottery-game-s">
                    <div class="lottery-game-price">1000 金币/次</div>
                    <div class="lottery-game-type" id="J_GamePlayRotateType">
                        <a href="javascript:;" class="rotate-info-type-1" data-type="4"></a>
                        <a href="javascript:;" class="rotate-info-type-2"  data-type="3"></a>
                        <a href="javascript:;" class="rotate-info-type-3"  data-type="2"></a>
                        <a href="javascript:;" class="rotate-info-type-4 active"  data-type="1"></a>
                    </div>
                </div>
            </div>
            <div class="prize-record-rank">
                <div class="prize-rank-container">
                    <div class="rank-tab" id="J_RotateRankTab">
                        <a href="javascript:;" class="active">获奖名单</a>
                        <a href="javascript:;">日榜</a>
                        <a href="javascript:;">周榜</a>
                    </div>
                    <div class="rank-cont">
                        <div class="rank-content  active">
                            <ul class="rc-realtime-list" id="J_RotateInfoList">
                            </ul>
                        </div>
                        <div class="rank-content" id="J_GameRotateRankDay">
                            <ul class="rc-list rc-list-title">
                                <li class="num">排名</li>
                                <li class="nickname">昵称</li>
                                <li class="worth">奖励价值</li>
                            </ul>
                        </div>
                        <div class="rank-content" id="J_GameRotateRankWeek">
                            <ul class="rc-list rc-list-title">
                                <li class="num">排名</li>
                                <li class="nickname">昵称</li>
                                <li class="worth">奖励价值</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
            <a href="/member/order/winning" target="_blank" class="my-prize-record"></a>
        </div>
    </div>
<script type="text/javascript">
    var GameLottery = {
        Data:{
            GameIDS:[1000, 2000, 3000, 4000],//游戏 四个价格对应的 ID
            Rotate:{
                TimeOut:2000,
                LotteryType:1,
                LotteryCount:1,
                IsTure:false
            },
            Data:null
        },
        Init:function(){
            var _This = GameLottery;
            var _ThisPageData = {
                PageParm: {
                    P_Get: true,
                    Loading: false, //加载中
                    Total: null,       //总条数
                    MaxCode: "",    //MaxCode
                    Start: 0,       //开始
                    Length: 4      //页长度
                }
            };
            //转盘游戏信息
            $.ajax({
                url: '/ajax/base.lotteryinfo',
                type: 'get',
                dataType: 'json',
                success: function (data) {
                    if (data.flag !== 0) {
                        $.CommonMain.Modal_Tip("Error!"+data.flag);
                        return;
                    }
                    _This.Data.Data = data;
                }
            });
            //获奖名单
            $.ajax({
                url: '/ajax/user.order-lottery.page',
                type: 'post',
                dataType: 'json',
                data: {
                    P_Get: _ThisPageData.PageParm.P_Get,
                    P_Total: _ThisPageData.PageParm.Total,
                    P_MaxCode: _ThisPageData.PageParm.MaxCode,
                    iDisplayStart: _ThisPageData.PageParm.Start,
                    iDisplayLength: _ThisPageData.PageParm.Length,
                    Sort_Col:"Create_Date",
                    Sort_Dir: "DESC"
                },
                success: function (data) {
                    if (data.flag !== 0) {
                        $.CommonMain.Modal_Tip("Error!"+data.flag);
                        return;
                    }
                    data.aaData.reverse();
                    _.forEach(data.aaData, function(value, key) {
                        _This.GameLottery_DataRender(value);
                    });

                }
            });
            //日榜
            $.ajax({
                url: '/ajax/user.order-lottery.lotteryrank',
                type: 'post',
                dataType: 'json',
                data: {
                    Length: 10,
                    Type: 1
                },
                success: function (data) {
                    if (data.flag !== 0) {
                        $.CommonMain.Modal_Tip("Error!"+data.flag);
                        return;
                    }
                    ShowRankList('J_GameRotateRankDay', data.data);
                }
            });
            //周榜
            $.ajax({
                url: '/ajax/user.order-lottery.lotteryrank',
                type: 'post',
                dataType: 'json',
                data: {
                    Length: 10,
                    Type: 2
                },
                success: function (data) {
                    if (data.flag !== 0) {
                        $.CommonMain.Modal_Tip("Error!"+data.flag);
                        return;
                    }
                    ShowRankList('J_GameRotateRankWeek', data.data);
                }
            });
            //显示榜
            function ShowRankList(EmeID, Data){
                var ul = '';
                _.forEach(Data, function(value, key) {
                    ul += '<ul class="rc-list">' +
                            '<li class="num"><span class="top-'+(key+1)+'">'+(key+1)+'</span></li>' +
                            '<li class="nickname">'+value.NickName+'</li>' +
                            '<li class="worth">'+value.SUM_WinningValue+'</li>' +
                            '</ul>';
                });
                $('#'+EmeID).append(ul);
            }
            //切换排行榜
            $('#J_RotateRankTab').on('click','a',function(){
                var index = $(this).index();
                $(this).addClass("active").siblings().removeClass("active");
                $('.rank-cont > .rank-content').eq(index).addClass('active').siblings().removeClass('active');
            });
            //关闭按钮
            $("#J_RotateClosed").on("click",function () {
                $("#J_GameRotateC").remove();
            });

            var dataurl= $("#J_GamePlayRotateBg").data("lazy");
            var dataimg = $("#J_GamePlayRotateBg").attr("src");
            //切换价格按钮
            $("#J_GamePlayRotateType").on("click","a",function () {
                if(_This.Data.Rotate.IsTure) return;
                var index = $(this).data("type");
                var p = [1000,2500,5000,10000];
                $('.lottery-game-price').text( p[(index-1)] + ' 金币/次');
                _This.Data.Rotate.LotteryType = index;

                $('#J_GameLotteryPlayImg').attr('src', _VirtualPath.Static+'main/template/imax/image/lottery/rotate/lottery/playbtn-'+(5-index)+'.png');

                $(this).addClass("active").siblings().removeClass("active");
                $("#J_G_LotteryImg").removeClass().addClass("g-lottery-img g-lottery-img-"+index);
            });

            $('#J_GamePlayBtn').hover(function () {
                $("#J_GamePlayRotateBg").attr("src",dataurl);
            },function () {
                $("#J_GamePlayRotateBg").attr("src",dataimg);
            });
            $('#J_GamePlayBtn').click(function() {
                if (!$.CommonMain.LoginCheck()) {
                    return;
                }
                if(_This.Data.Rotate.IsTure) return; // 如果在执行就退出
                _This.Data.Rotate.IsTure = true; // 标志为 在执行
                $.CommonMainRoom.SocketEmit.Lottery({
                    Lottery_ID:_This.Data.GameIDS[ (_This.Data.Rotate.LotteryType-1) ]
                });

            });
        },
        //显示获取名单Ajax
        GameLottery_DataRender:function (data) {
            var _Item = '<li><span class="rl-time">'+moment(data.Create_Date).format('HH:mm:ss')+'</span><a href="javascript:;" class="rl-nickname">'+data.User_NickName+'</a>获得了<span class="rl-total">'+data.Winning_Text+ '</span></li>';
            $("#J_RotateInfoList").append(_Item);
        },
        //Socket中奖数据，执行转盘。
        GameLotteryResult:function (type, data) {
            var _This = GameLottery
            var index = _This.GameLotteryGetIndex(_This.Data.Data.data,data.LotteryWinningList);
            if(index === -1){
                $.CommonMain.Modal_Tip("系统忙，请稍后重试！");
                return;
            }else{
                var angle = [0,40,80,120,160,200,240,280,320];
                _This.GameLotteryExec(_This.Data.Data.data["key"+_This.Data.Rotate.LotteryType][index].ID,angle[index],data)
            }
        },
        //Socket中奖数据，显示到列表
        GameLotteryResultShow:function (type, data){
            var _This = GameLottery;
            setTimeout(function () {
                if($("#J_RotateInfoList li").length>10){
                    $("#J_RotateInfoList li").eq(0).remove();
                };
                var _Item = '<li><span class="rl-time">'+moment(data.Create_Date).format('HH:mm:ss')+'</span><a href="javascript:;" class="rl-nickname">'+data.RoomUserInfo.NickName+'</a>获得了<span class="rl-total">'+( (data.LotteryWinningList[0] != undefined) ? data.LotteryWinningList[0].Name : data.LotteryWinningList[0].Name )+ '</span></li>';
                $("#J_RotateInfoList").append(_Item);
            }, _This.Data.Rotate.TimeOut)
        },
        //获取中奖信息索引
        GameLotteryGetIndex:function (Arr, Res) {
            var _This = GameLottery;
            for(var i=0;i<Arr["key"+_This.Data.Rotate.LotteryType].length;i++){
                var value = Arr["key"+_This.Data.Rotate.LotteryType][i];
                if(value.Item_ID == Res[0].Item_ID){
                    return i;
                }
            }
            return -1;
        },
        GameLottery_Notice:function(data){
            var _This = GameLottery;
            if(data.flag === -2){
                _This.Data.Rotate.IsTure = false;
            }
        },
        //转盘效果
        GameLotteryExec:function(awards, angle, data) {
            var _This = GameLottery;
            _This.Data.Rotate.IsTure = true;
            $('#J_GamePlayBtn').stopRotate();
            $('#J_GamePlayBtn').rotate({
                angle: 0,
                duration: _This.Data.Rotate.TimeOut, //旋转时间
                animateTo: angle + 1080, //让它根据得出来的结果加上360*圈 度旋转
                callback: function() {
                    _This.Data.Rotate.IsTure = false; // 标志为 执行完毕
                    // GameLotteryResultShow(data);
                }
            });
        }
    }
    GameLottery.Init();
</script>
</div>